package me.zixing.java.guiandthread.domain;

import lombok.Getter;

import java.util.List;
import java.util.concurrent.*;

/**
 * Created by bingh on 2017/11/13.
 */
public class Track {
    private int part;
    private int length;
    private Executor executor ;
    private static CountDownLatch latch;

    public Track(int part,int length){
        this.part = part;
        this.length = length;
    }

    public static CountDownLatch getLatch(){
        return latch;
    }

    public void start(List<SportableContent> sportableContentList) throws Exception{
        if(sportableContentList.size() > part){
            throw new Exception("运动员太多了，跑道放不下");
        }
        executor = Executors.newFixedThreadPool(sportableContentList.size());
        latch = new CountDownLatch(sportableContentList.size());
        for (SportableContent sportableContent:sportableContentList) {
            executor.execute(sportableContent);
            latch.countDown();
        }
    }
}
